package shining365.programmableweb.data.collect;

import java.io.IOException;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import javax.annotation.Resource;
import javax.xml.bind.JAXBException;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import shining365.programmableweb.data.common.Utils;
import shining365.programmableweb.data.model.Mashup;
import shining365.programmableweb.data.model.Mashups;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"/applicationContext.xml"})
public class MarshallMashups {
	
	@Test
	public void marshall() throws JAXBException, IOException {
		List<Mashup> mashupList = dao.findAllMashups();
		Collections.sort(mashupList, new Comparator<Mashup>(){
			@Override
			public int compare(Mashup o1, Mashup o2) {
				return o1.getDate().compare(o2.getDate());
			}
		});
		
		Mashups mashups = new Mashups();
		mashups.getMashup().addAll(mashupList);
		
		Utils.marshallToFile(mashups, "doc/simpleprogrammableweb.mashups.xml");
	}

	@Resource
	private Dao dao;
}
